package com.jimmy.medical.controller;

import com.jimmy.medical.entity.Message;
import com.jimmy.medical.entity.PhoneCall;
import com.jimmy.medical.model.AjaxResult;
import com.jimmy.medical.model.SignInfo;
import com.jimmy.medical.service.IServiceFlowOrderService;
import com.jimmy.medical.util.AjaxUtils;
import com.jimmy.medical.util.Func_T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/serviceFlow")
public class ServiceFlowOrderController {

    @Autowired
    private IServiceFlowOrderService serviceFlowOrderService;

    /**
     * 初步处理
     *
     * @param userId
     * @param： flowOrderId
     * @return
     */
    @RequestMapping("/simpleProcess")
    @ResponseBody
    public AjaxResult<Long> simpleProcess(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return serviceFlowOrderService.saveSimpleProcess(flowOrderId, userId);
            }
        });
    }

    /**
     * 服务办理
     *
     * @param info
     * @return
     */
    @RequestMapping("/serviceSign")
    @ResponseBody
    public AjaxResult<Long> serviceSign(final SignInfo info) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return serviceFlowOrderService.saveServiceSignInfo(info);
            }
        });
    }

    /**
     * 电话通知
     *
     * @param call
     * @return
     */
    @RequestMapping("/noticeToCustomer")
    @ResponseBody
    public AjaxResult<Long> noticeToCustomer(final PhoneCall call) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return serviceFlowOrderService.saveNoticeInfo(call);
            }
        });
    }

    /**
     * 短信通知
     *
     * @param message
     * @return
     */
    @RequestMapping("/messageToCustomer")
    @ResponseBody
    public AjaxResult<Long> messageToCustomer(final Message message) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return serviceFlowOrderService.saveMessageFlow(message);
            }
        });
    }

    /**
     * 费用处理
     *
     * @param flowOrderId
     * @param userId
     * @return
     */
    @RequestMapping("/feeProcess")
    @ResponseBody
    public AjaxResult<Long> feeProcess(final Long flowOrderId, final Long userId) {
        if(serviceFlowOrderService.isFeeProcess(flowOrderId)) {
            //已处理
            return AjaxUtils.process(new Func_T<Long>() {
                @Override
                public Long invoke() throws Exception {
                    return serviceFlowOrderService.saveFeeProcess(flowOrderId, userId);
                }
            });
        } else {
            AjaxResult result = new AjaxResult();
            result.setSuccess(false);
            result.setMessage("当前用户存在未处理费用,无法提交费用处理");
            return result;
        }
    }

    /**
     * 完成取号
     * @return
     */
    @RequestMapping("/submitService")
    @ResponseBody
    public AjaxResult<String> submitService(final Long flowOrderId, final  Long userId) {
        return AjaxUtils.process(new Func_T<String>() {
            @Override
            public String invoke() throws Exception {
                serviceFlowOrderService.submitService(flowOrderId, userId);
                return "200";
            }
        });
    }
}
